package com.bw.unit3.uitl

import android.content.Context
import android.text.TextUtils
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter

/**
 *
 * @ClassName: LoginInterceptor
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/20 5:31 PM
 * @Version: 1.0
 */
@Interceptor(priority = 1, name = "LoginInterceptor")
class LoginInterceptor : IInterceptor {
    override fun init(context: Context?) {
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {

        if (TextUtils.isEmpty(SpUtil.getString("token")) && !postcard?.path.equals("/login/LoginActivity")) {
            ARouter.getInstance().build("/login/LoginActivity").navigation()
            callback?.onInterrupt(null)

        } else {
            callback?.onContinue(postcard)
        }
    }
}